<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2023-03-10
 * Time: 16:58:06
 * Info: 后台日志
 */

namespace app\admin\controller;

use think\facade\View;
use app\common\model\LoginLog as LoginLogModel;
use app\common\model\SystemLog as SystemLogModel;

class AdminLog extends Base
{

    /**
     * 后台登录日志
     * @return string|void
     */
    public function loginLog()
    {
        if ($this->request->isAjax()) {
            $param = [
                'page'  => (int)$this->request->param('page'),
                'limit' => (int)$this->request->param('limit'),
                'key'   => $this->request->param('key'),
            ];
            $data  = LoginLogModel::getLogList($param);
            $this->success('ok', $data['list'], $data['count']);
        }

        return View::fetch();
    }

    /**
     * todo
     * @return void
     */
    public function loginLogDel()
    {
        $type = $this->request->param('type');
        if ($type == 1) {
            //删除全部
            LoginLogModel::where("1=1")->delete();
        } else {
            $lastTime = time() - 3600 * 24 * 30;
            LoginLogModel::whereTime('create_time', '<', $lastTime)->delete();
        }
        $this->success('删除成功');
    }

    /**
     * 后台操作日志
     * @return string|void
     */
    public function systemLog()
    {
        if ($this->request->isAjax()) {
            $param = [
                'page'  => (int)$this->request->param('page'),
                'limit' => (int)$this->request->param('limit'),
                'key'   => $this->request->param('key'),
            ];
            $data  = SystemLogModel::getLogList($param);
            $this->success('ok', $data['list'], $data['count']);
        }

        return View::fetch();
    }

    /**
     * todo
     * @return string|void
     */
    public function systemLogDel()
    {
        $type = $this->request->param('type');
        if ($type == 1) {
            //删除全部
            SystemLogModel::where("1=1")->delete();
        } else {
            $lastTime = time() - 3600 * 24 * 30;
            SystemLogModel::whereTime('create_time', '<', $lastTime)->delete();
        }
        $this->success('删除成功');
    }

}
